package com.base.taskreports.reports.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.base.taskreports.reports.dao.master.TBatchDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.taskreports.reports.entiyt.master.TBatchEntity;
import com.base.taskreports.reports.service.TBatchService;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张玉涛
 * @since 2021-11-09
 */
@DS("master")
@Service("tBatchService")
public class TBatchServiceImpl extends ServiceImpl<TBatchDao, TBatchEntity> implements TBatchService {

	@Autowired
	private TBatchDao tBatchDao;

	/**
	 * 以天为单位判断是否有正在执行的跑批任务
	 * @param strDate
	 * @return
	 */
	public Boolean isFinished(String strDate){
		QueryWrapper<TBatchEntity> queryWrapper = new QueryWrapper() ;
		queryWrapper.eq("task_date", strDate ) ;
		queryWrapper.eq("is_finished","0") ;

		List<TBatchEntity> list = this.list(queryWrapper) ;

		return list.size()>0?true:false ;
	}

	/**
	 * 判断是否有某个模块跑批任务正在执行的
	 * @param taskId
	 * @param strDate
	 * @return
	 */
	public Boolean isFinishedLike(String taskId,String strDate){
		QueryWrapper<TBatchEntity> queryWrapper = new QueryWrapper() ;
		queryWrapper.likeRight("task_id",taskId) ;
		queryWrapper.eq("task_date", strDate ) ;
		queryWrapper.eq("is_finished","0") ;

		List<TBatchEntity> list = this.list(queryWrapper) ;

		return list.size()>0?true:false ;
	}

	/**
	 * 判断是否有某个指标跑批任务正在执行的
	 * @param taskId
	 * @param strDate
	 * @return
	 */
	public Boolean isFinished(String taskId,String strDate){
		QueryWrapper<TBatchEntity> queryWrapper = new QueryWrapper() ;
		queryWrapper.eq("task_id",taskId) ;
		queryWrapper.eq("task_date", strDate ) ;
		queryWrapper.eq("is_finished","0") ;

		List<TBatchEntity> list = this.list(queryWrapper) ;

		return list.size()>0?true:false ;
	}
	
	@Override
	public void saveTBatch(TBatchEntity tBatchEntity) {
		// TODO Auto-generated method stub
		//this.save(tBatchEntity);
		int insert = tBatchDao.insert(tBatchEntity);
	}

	@Override
	public void updateTBatch(TBatchEntity tBatchEntity) {
		// TODO Auto-generated method stub
		this.updateById(tBatchEntity);
	}

}
